home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / misc / TownMaze.lha / TownMaze / src.lzh / townmaze.h < prev    next >
C/C++ Source or Header  |  1991-08-04  |  5KB  |  186 lines

  1. /*
  2. ** townmaze.h  Copyright 1991 Kent Paul Dolan,
  3. **             Mountain View, CA, USA 94039-0755
  4. **
  5. ** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  6. ** May be freely used or modified in any non-commercial work.  Copyrighted
  7. ** only to prevent patenting by someone else.
  8. */
  9.  
  10. /*
  11. ** Avoid infinite loops in several routines.
  12. */
  13.  
  14. #define MAXTRIES 5000
  15.  
  16. /*
  17. ** Define PROGRESS as 1 to see a "walking progress" line of routines
  18. ** announcing themselves as they run, 0 otherwise.
  19. **
  20. ** Define SHOWSTART as 1 to see a debug maze that shows the situation
  21. ** after the gates and courts are added but before the streets are 
  22. ** otherwise built; 0 to skip it.
  23. **
  24. ** Define SHOWEND as 1 to see a debug maze that shows the situation
  25. ** after the maze is completed; 0 to skip it;
  26. **
  27. ** Define HEADER as 1 to see the parameter values echoed back just above
  28. ** the maze, 0 to suppress the header.
  29. **
  30. ** Define RAND48 in the makefile  to use the srand48() and lrand48()
  31. ** functions instead of the srandom() and random() functions.
  32. */
  33.  
  34. #define PROGRESS 0
  35. #define SHOWSTART 0
  36. #define SHOWEND 0
  37. #define HEADER 1
  38.  
  39. #ifdef RAND48
  40. #include <math.h>
  41. #define RANDOM lrand48
  42. #define SEEDRANDOM srand48
  43. #else
  44. #define RANDOM random
  45. #define SEEDRANDOM srandom
  46. #endif
  47.  
  48. /*
  49. ** Control for defintion (allocation)  of globals in main only,
  50. ** declaration only elsewhere.
  51. */
  52.  
  53. #ifdef MAINLINE
  54. #define SIDETRACK
  55. #else
  56. #define SIDETRACK extern
  57. #endif
  58.  
  59. /*
  60. **
  61. ** The maze is sized in terms of X cells by Y cells, and of X charcters
  62. ** by Y characters; there are 2*cells+1 characters in each maze
  63. ** direction.  For purposes of screen display, the horizontal direction
  64. ** is X and the vertical direction is Y, and the origin is at the top
  65. ** left, with Y positive going down and X positive going right. 
  66. **
  67. ** For various reasons in the code, a maze must have at least 5 cells
  68. ** per side (which will be a very boring maze indeed.  Corner cells are
  69. ** not used, to ease the design problem.
  70. **
  71. ** The primary maze determinant is its size in characters; this
  72. ** must be odd in both dimensions.
  73. **
  74. */
  75.  
  76. /*
  77. ** P A R A M E T E R S
  78. **
  79. ** -h mazeheight         -- Y size in characters
  80. ** -w mazewidth          -- X size in characters
  81. **    listsize           -- number of cells in the cell array; computed global
  82. ** -r randomseed         -- use to get the same maze again; replaces clock
  83. **                          seed; seed used is reported in the header for use
  84. **                          in a repeat run.
  85. ** -g mazegates          -- number of streets to start at the city wall
  86. ** -l leftgates          -- number of them to leave doors leading outside on
  87. ** -c mazecourts         -- number of streets to start away from the city wall
  88. ** -u mazeunused         -- number of cells to leave unused in the maze
  89. ** -s mazestraightness   -- times per thousand to retry on average before
  90. **                          accepting a random cell that makes a street turn
  91. **                          rather than go straight
  92. **
  93. ** All parameters have default values.  Listsize is computed when mazeheight
  94. ** and mazewidth are known.
  95. **
  96. */
  97.  
  98. #ifdef MAINLINE
  99. int mazeheight = 23;
  100. int mazewidth  = 77;
  101. int listsize;
  102. long randomseed;
  103. int mazegates  =  4;
  104. int leftgates  =  2;
  105. int mazecourts =  0;
  106. int mazeunused = 0;
  107. int mazestraightness = 750;
  108. #else
  109. extern int mazeheight;
  110. extern int mazewidth;
  111. extern int listsize;
  112. extern long randomseed;
  113. extern int mazegates;
  114. extern int leftgates;
  115. extern int mazecourts;
  116. extern int mazeunused;
  117. extern int mazestraightness;
  118. #endif
  119.  
  120. /*
  121. ** T Y P E D E F S
  122. */
  123.  
  124. typedef struct dlelem
  125. {
  126.    int next;
  127.    int prev;
  128.    int status;
  129.    int streetnum;
  130.    int streetdir;
  131. } DLENODE;
  132.  
  133. /*
  134. ** M A Z E  A R R A Y S
  135. */
  136.  
  137. /*
  138. ** The cell list used for storing cell status information.  Although the
  139. ** maze is 2D, this list is kept 1D to make it simple to use list array
  140. ** indices as link list "pointers".
  141. */
  142.  
  143. SIDETRACK DLENODE *statlist;
  144. SIDETRACK int isolated,  street,  live,  dead,   unused;
  145. SIDETRACK int isolatedct,streetct,livect,deadct, unusedct;
  146. SIDETRACK int streetnumct;
  147.  
  148. /*
  149. ** The maze used for display.
  150. */
  151.  
  152. SIDETRACK char **cmaze;
  153.  
  154. /*
  155. ** P R I N T I N G  S Y M B O L S
  156. */
  157.  
  158. /*
  159. ** maze drawing elements for ascii screen presentation
  160. */
  161.  
  162. #define WALL  '#'
  163. #define VDOOR '|'
  164. #define HDOOR '-'
  165. #define BLANK ' '
  166.  
  167. /*
  168. ** D E F I N E D  C O N S T A N T S
  169. */
  170.  
  171. /*
  172. ** status of maze locations
  173. */
  174.  
  175. #define ISOLATED  1
  176. #define LIVE      2
  177. #define DEAD      3
  178. #define STREET    4
  179. #define UNUSED    5
  180.  
  181. /*
  182. ** Bogus null pointer for indices used as pointers, since zero is valid.
  183. */
  184.  
  185. #define NOPOINTER -1
  186.